var t = require("../../../mybehaviors/location/location"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        SEARCH_URL: "plugin.hotel.frontend.hotel.goods.get-hotel-goods-by-title",
        address: "",
        point: {
            lat: "",
            lng: ""
        },
        city: "",
        title: "",
        start_time: "",
        end_time: "",
        price: "",
        star: "",
        category: "",
        loading: !1,
        allLoaded: !1,
        goload: !0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        list_arr: [],
        search_value: "",
        toolbar: !1,
        PageNameList: {}
    },
    onLoad: function(t) {
        var a = this;
        t.start && this.setData({
            start_time: t.start
        }), t.star && this.setData({
            star: t.star
        }), t.end && this.setData({
            end_time: t.end
        }), t.price && this.setData({
            price: t.price
        }), t.category && this.setData({
            category: t.category
        }), this.getCustomizeHotelHead(), this._getLocation(function() {
            a.search();
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.searchMore() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    search: function() {
        var t = this, e = a.getNetAddresss(t.data.SEARCH_URL);
        e += "&lng=" + this.data.point.lng, e += "&lat=" + this.data.point.lat, e += "&city_name=" + t.data.city, 
        e += "&page=" + this.data.page, e += "&entrance_time=" + (this.data.start_time ? this.data.start_time : ""), 
        e += "&price=" + (this.data.price ? this.data.price : ""), e += "&star_rated=" + (this.data.star ? this.data.star : ""), 
        e += "&category_id=" + (this.data.category ? this.data.category : ""), e += "&leave_at=" + (this.data.end_time ? this.data.end_time : ""), 
        e += "&kwd=" + (this.data.search_value ? this.data.search_value : ""), a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result && t.setData({
                    list_arr: e.data.data,
                    total_page: e.data.last_page
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getCustomizeHotelHead: function() {
        var t = this, e = "";
        try {
            var i = wx.getStorageSync("customizeHotelHead");
            i && (e = i);
        } catch (t) {}
        if (a._isTextEmpty(e)) {
            var s = a.getNetAddresss("plugin.hotel.frontend.hotel.get-hotel-info.get-custom-name");
            a._getNetWork({
                url: s,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        t.setData({
                            PageNameList: e.data
                        }), wx.setNavigationBarTitle({
                            title: (e.data.PageNameList.hotels, e.data.PageNameList.hotels + "搜索页")
                        });
                        try {
                            wx.setStorageSync("customizeHotelHead", JSON.stringify(e.data));
                        } catch (t) {
                            console.log(t);
                        }
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        } else this.setData({
            PageNameList: JSON.parse(e)
        }), wx.setNavigationBarTitle({
            title: this.data.PageNameList.hotels + "搜索页"
        });
    },
    gotoSearch: function() {
        this.initData(), this.search();
    },
    initData: function() {
        this.setData({
            page: 1,
            total_page: 0,
            goload: !0,
            loading: !0,
            allLoaded: !1,
            isLoadMore: !0,
            list_arr: []
        });
    },
    searchMore: function() {
        var t = this;
        if (this.data.page != this.data.total_page) if (this.data.page >= this.data.total_page) this.setData({
            loading: !0,
            allLoaded: !0
        }); else {
            this.setData({
                page: this.data.page + 1
            });
            var e = a.getNetAddresss(t.data.SEARCH_URL);
            e += "&lng=" + this.data.point.lng, e += "&lat=" + this.data.point.lat, e += "&city_name=" + this.data.city, 
            e += "&page=" + this.data.page, e += "&entrance_time=" + (this.data.start_time ? this.data.start_time : ""), 
            e += "&price=" + (this.data.price ? this.data.price : ""), e += "&star_rated=" + (this.data.star ? this.data.star : ""), 
            e += "&category_id=" + (this.data.category ? this.data.category : ""), e += "&leave_at=" + (this.data.end_time ? this.data.end_time : ""), 
            e += "&kwd=" + (this.data.search_value ? this.data.search_value : ""), a._getNetWork({
                url: e,
                success: function(a) {
                    var e = a.data;
                    1 == e.result ? t.setData({
                        loading: !1,
                        allLoaded: !1,
                        list_arr: t.data.list_arr.concat(e.data.data)
                    }) : t.setData({
                        page: t.data.page - 1,
                        loading: !0,
                        allLoaded: !0,
                        isLoadMore: !1
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    seainp: function(t) {
        var a = t.detail.value;
        this.setData({
            search_value: a
        });
    }
});